package com.mall.shopping.converter;


import com.mall.shopping.dal.entitys.Item;
import com.mall.shopping.dto.ProductDetailDto;
import org.mapstruct.Mapper;

import java.util.Arrays;

/**
 * <h1> ProductDetailConvert </h1>
 * Created by GaoJia
 * Date  2021/11/2 10:12
 */
@Mapper(componentModel = "spring")
public class ProductDetailConvert {

    // 直接 使用 set get 赋值
    public static ProductDetailDto item2DetailDto(Item item){
        ProductDetailDto productDetailDto = new ProductDetailDto();

        productDetailDto.setProductId(item.getId());
        productDetailDto.setProductName(item.getTitle());
        productDetailDto.setSalePrice(item.getPrice());
        productDetailDto.setSubTitle(item.getSellPoint());

        productDetailDto.setDetail("");
        productDetailDto.setProductImageBig(item.getImageBig());
        productDetailDto.setProductImageSmall(Arrays.asList(item.getImages()));

        if(item.getLimitNum()==null){
            productDetailDto.setLimitNum(Long.valueOf(item.getNum()));
        }else if(item.getLimitNum()<0&&item.getNum()<0) {
            productDetailDto.setLimitNum((long) 10);
        }else{
            productDetailDto.setLimitNum(Long.valueOf(item.getLimitNum()));
        }
        return productDetailDto;
    }
}
